From e3f60a7c99fa04e8d80b9427391ae0b697fca2b5 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 22 Oct 2014 14:35:23 +0200 Subject: [PATCH] Extract custom build tests and prefix with "old_" --- tests/test_cargo_compile.rs | 394 ------------------ tests/test_cargo_compile_old_custom_build.rs | 401 +++++++++++++++++++ tests/tests.rs | 1 + 3 files changed, 402 insertions(+), 394 deletions(-) create mode 100644 tests/test_cargo_compile_old_custom_build.rs diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 219de6acf..2e1774553 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -509,307 +509,6 @@ version required: * // test!(compiling_project_with_invalid_manifest) -test!(custom_build { - let mut build = project("builder"); - build = build - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] name = "foo" - "#) - .file("src/foo.rs", r#" - fn main() { println!("Hello!"); } - "#); - assert_that(build.cargo_process("build"), - execs().with_status(0)); - - - let mut p = project("foo"); - p = p - .file("Cargo.toml", format!(r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - build = '{}' - - [[bin]] name = "foo" - "#, build.bin("foo").display())) - .file("src/foo.rs", r#" - fn main() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(0) - .with_stdout(format!(" Compiling foo v0.5.0 ({})\n", - p.url())) - .with_stderr("")); -}) - -test!(custom_multiple_build { - let mut build1 = project("builder1"); - build1 = build1 - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] name = "foo" - "#) - .file("src/foo.rs", r#" - fn main() { - let args = ::std::os::args(); - assert_eq!(args[1], "hello".to_string()); - assert_eq!(args[2], "world".to_string()); - } - "#); - assert_that(build1.cargo_process("build"), - execs().with_status(0)); - - let mut build2 = project("builder2"); - build2 = build2 - .file("Cargo.toml", r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] name = "bar" - "#) - .file("src/bar.rs", r#" - fn main() { - let args = ::std::os::args(); - assert_eq!(args[1], "cargo".to_string()); - } - "#); - assert_that(build2.cargo_process("build"), - execs().with_status(0)); - - let mut p = project("foo"); - p = p - .file("Cargo.toml", format!(r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - build = [ '{} hello world', '{} cargo' ] - - [[bin]] name = "foo" - "#, build1.bin("foo").display(), build2.bin("bar").display())) - .file("src/foo.rs", r#" - fn main() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(0) - .with_stdout(format!(" Compiling foo v0.5.0 ({})\n", - p.url())) - .with_stderr("")); -}) - -test!(custom_build_failure { - let mut build = project("builder"); - build = build - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] - name = "foo" - "#) - .file("src/foo.rs", r#" - fn main() { panic!("nope") } - "#); - assert_that(build.cargo_process("build"), execs().with_status(0)); - - - let mut p = project("foo"); - p = p - .file("Cargo.toml", format!(r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - build = '{}' - - [[bin]] - name = "foo" - "#, build.bin("foo").display())) - .file("src/foo.rs", r#" - fn main() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(101).with_stderr(format!("\ -Failed to run custom build command for `foo v0.5.0 ({dir}) -Process didn't exit successfully: `{}` (status=101)\n\ ---- stderr\n\ -task '
' panicked at 'nope', {filename}:2\n\ -\n\ -", build.bin("foo").display(), filename = format!("src{}foo.rs", path::SEP), - dir = p.url()))); -}) - -test!(custom_second_build_failure { - let mut build1 = project("builder1"); - build1 = build1 - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] name = "foo" - "#) - .file("src/foo.rs", r#" - fn main() { println!("Hello!"); } - "#); - assert_that(build1.cargo_process("build"), - execs().with_status(0)); - - let mut build2 = project("builder2"); - build2 = build2 - .file("Cargo.toml", r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] - name = "bar" - "#) - .file("src/bar.rs", r#" - fn main() { panic!("nope") } - "#); - assert_that(build2.cargo_process("build"), execs().with_status(0)); - - - let mut p = project("foo"); - p = p - .file("Cargo.toml", format!(r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - build = [ '{}', '{}' ] - - [[bin]] - name = "foo" - "#, build1.bin("foo").display(), build2.bin("bar").display())) - .file("src/foo.rs", r#" - fn main() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(101).with_stderr(format!("\ -Failed to run custom build command for `foo v0.5.0 ({dir}) -Process didn't exit successfully: `{}` (status=101)\n\ ---- stderr\n\ -task '
' panicked at 'nope', {filename}:2\n\ -\n\ -", build2.bin("bar").display(), filename = format!("src{}bar.rs", path::SEP), - dir = p.url()))); -}) - -test!(custom_build_env_vars { - let bar = project("bar") - .file("Cargo.toml", r#" - [package] - name = "bar-bar" - version = "0.0.1" - authors = [] - build = "true" - "#) - .file("src/lib.rs", ""); - bar.build(); - - let mut p = project("foo"); - let mut build = project("builder"); - build = build - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [features] - foo = [] - - [[bin]] - name = "foo" - "#) - .file("src/foo.rs", format!(r#" - use std::os; - use std::io::fs::PathExtensions; - fn main() {{ - let _ncpus = os::getenv("NUM_JOBS").unwrap(); - let _feat = os::getenv("CARGO_FEATURE_FOO").unwrap(); - let debug = os::getenv("DEBUG").unwrap(); - assert_eq!(debug.as_slice(), "true"); - - let opt = os::getenv("OPT_LEVEL").unwrap(); - assert_eq!(opt.as_slice(), "0"); - - let opt = os::getenv("PROFILE").unwrap(); - assert_eq!(opt.as_slice(), "compile"); - - let out = os::getenv("OUT_DIR").unwrap(); - assert!(out.as_slice().starts_with(r"{0}")); - assert!(Path::new(out).is_dir()); - - let out = os::getenv("DEP_BAR_BAR_OUT_DIR").unwrap(); - assert!(out.as_slice().starts_with(r"{0}")); - assert!(Path::new(out).is_dir()); - - let out = os::getenv("CARGO_MANIFEST_DIR").unwrap(); - let p1 = Path::new(out); - let p2 = os::make_absolute(&Path::new(file!()).dir_path().dir_path()); - assert!(p1 == p2, "{{}} != {{}}", p1.display(), p2.display()); - }} - "#, - p.root().join("target").join("native").display())); - assert_that(build.cargo_process("build").arg("--features").arg("foo"), - execs().with_status(0)); - - - p = p - .file("Cargo.toml", format!(r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - build = '{}' - - [features] - foo = [] - - [[bin]] - name = "foo" - - [dependencies.bar-bar] - path = '{}' - "#, build.bin("foo").display(), bar.root().display())) - .file("src/foo.rs", r#" - fn main() {} - "#); - assert_that(p.cargo_process("build").arg("--features").arg("foo"), - execs().with_status(0)); -}) - test!(crate_version_env_vars { let p = project("foo") .file("Cargo.toml", r#" @@ -857,99 +556,6 @@ test!(crate_version_env_vars { execs().with_status(0)); }) -test!(custom_build_in_dependency { - let mut p = project("foo"); - let mut build = project("builder"); - build = build - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] - name = "foo" - "#) - .file("src/foo.rs", format!(r#" - use std::os; - fn main() {{ - assert!(os::getenv("OUT_DIR").unwrap().as_slice() - .starts_with(r"{}")); - }} - "#, - p.root().join("target/native/bar-").display())); - assert_that(build.cargo_process("build"), execs().with_status(0)); - - - p = p - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] - name = "foo" - [dependencies.bar] - path = "bar" - "#) - .file("src/foo.rs", r#" - extern crate bar; - fn main() { bar::bar() } - "#) - .file("bar/Cargo.toml", format!(r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - build = '{}' - "#, build.bin("foo").display())) - .file("bar/src/lib.rs", r#" - pub fn bar() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(0)); -}) - -// tests that custom build in dep can be built twice in a row - issue 227 -test!(custom_build_in_dependency_twice { - let p = project("foo") - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] - name = "foo" - [dependencies.bar] - path = "./bar" - "#) - .file("src/foo.rs", r#" - extern crate bar; - fn main() { bar::bar() } - "#) - .file("bar/Cargo.toml", format!(r#" - [project] - - name = "bar" - version = "0.0.1" - authors = ["wycats@example.com"] - build = '{}' - "#, "echo test")) - .file("bar/src/lib.rs", r#" - pub fn bar() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(0)); - assert_that(p.process(cargo_dir().join("cargo")).arg("build"), - execs().with_status(0)); -}) - // this is testing that src/.rs still works (for now) test!(many_crate_types_old_style_lib_location { let mut p = project("foo"); diff --git a/tests/test_cargo_compile_old_custom_build.rs b/tests/test_cargo_compile_old_custom_build.rs new file mode 100644 index 000000000..e48986fc6 --- /dev/null +++ b/tests/test_cargo_compile_old_custom_build.rs @@ -0,0 +1,401 @@ +use std::path; + +use support::{project, execs, cargo_dir}; +use hamcrest::{assert_that}; + +fn setup() { +} + +test!(old_custom_build { + let mut build = project("builder"); + build = build + .file("Cargo.toml", r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [[bin]] name = "foo" + "#) + .file("src/foo.rs", r#" + fn main() { println!("Hello!"); } + "#); + assert_that(build.cargo_process("build"), + execs().with_status(0)); + + + let mut p = project("foo"); + p = p + .file("Cargo.toml", format!(r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + build = '{}' + + [[bin]] name = "foo" + "#, build.bin("foo").display())) + .file("src/foo.rs", r#" + fn main() {} + "#); + assert_that(p.cargo_process("build"), + execs().with_status(0) + .with_stdout(format!(" Compiling foo v0.5.0 ({})\n", + p.url())) + .with_stderr("")); +}) + +test!(old_custom_multiple_build { + let mut build1 = project("builder1"); + build1 = build1 + .file("Cargo.toml", r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [[bin]] name = "foo" + "#) + .file("src/foo.rs", r#" + fn main() { + let args = ::std::os::args(); + assert_eq!(args[1], "hello".to_string()); + assert_eq!(args[2], "world".to_string()); + } + "#); + assert_that(build1.cargo_process("build"), + execs().with_status(0)); + + let mut build2 = project("builder2"); + build2 = build2 + .file("Cargo.toml", r#" + [project] + + name = "bar" + version = "0.5.0" + authors = ["wycats@example.com"] + + [[bin]] name = "bar" + "#) + .file("src/bar.rs", r#" + fn main() { + let args = ::std::os::args(); + assert_eq!(args[1], "cargo".to_string()); + } + "#); + assert_that(build2.cargo_process("build"), + execs().with_status(0)); + + let mut p = project("foo"); + p = p + .file("Cargo.toml", format!(r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + build = [ '{} hello world', '{} cargo' ] + + [[bin]] name = "foo" + "#, build1.bin("foo").display(), build2.bin("bar").display())) + .file("src/foo.rs", r#" + fn main() {} + "#); + assert_that(p.cargo_process("build"), + execs().with_status(0) + .with_stdout(format!(" Compiling foo v0.5.0 ({})\n", + p.url())) + .with_stderr("")); +}) + +test!(old_custom_build_failure { + let mut build = project("builder"); + build = build + .file("Cargo.toml", r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [[bin]] + name = "foo" + "#) + .file("src/foo.rs", r#" + fn main() { panic!("nope") } + "#); + assert_that(build.cargo_process("build"), execs().with_status(0)); + + + let mut p = project("foo"); + p = p + .file("Cargo.toml", format!(r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + build = '{}' + + [[bin]] + name = "foo" + "#, build.bin("foo").display())) + .file("src/foo.rs", r#" + fn main() {} + "#); + assert_that(p.cargo_process("build"), + execs().with_status(101).with_stderr(format!("\ +Failed to run custom build command for `foo v0.5.0 ({dir}) +Process didn't exit successfully: `{}` (status=101)\n\ +--- stderr\n\ +task '
' panicked at 'nope', {filename}:2\n\ +\n\ +", build.bin("foo").display(), filename = format!("src{}foo.rs", path::SEP), + dir = p.url()))); +}) + +test!(old_custom_second_build_failure { + let mut build1 = project("builder1"); + build1 = build1 + .file("Cargo.toml", r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [[bin]] name = "foo" + "#) + .file("src/foo.rs", r#" + fn main() { println!("Hello!"); } + "#); + assert_that(build1.cargo_process("build"), + execs().with_status(0)); + + let mut build2 = project("builder2"); + build2 = build2 + .file("Cargo.toml", r#" + [project] + + name = "bar" + version = "0.5.0" + authors = ["wycats@example.com"] + + [[bin]] + name = "bar" + "#) + .file("src/bar.rs", r#" + fn main() { panic!("nope") } + "#); + assert_that(build2.cargo_process("build"), execs().with_status(0)); + + + let mut p = project("foo"); + p = p + .file("Cargo.toml", format!(r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + build = [ '{}', '{}' ] + + [[bin]] + name = "foo" + "#, build1.bin("foo").display(), build2.bin("bar").display())) + .file("src/foo.rs", r#" + fn main() {} + "#); + assert_that(p.cargo_process("build"), + execs().with_status(101).with_stderr(format!("\ +Failed to run custom build command for `foo v0.5.0 ({dir}) +Process didn't exit successfully: `{}` (status=101)\n\ +--- stderr\n\ +task '
' panicked at 'nope', {filename}:2\n\ +\n\ +", build2.bin("bar").display(), filename = format!("src{}bar.rs", path::SEP), + dir = p.url()))); +}) + +test!(old_custom_build_env_vars { + let bar = project("bar") + .file("Cargo.toml", r#" + [package] + name = "bar-bar" + version = "0.0.1" + authors = [] + build = "true" + "#) + .file("src/lib.rs", ""); + bar.build(); + + let mut p = project("foo"); + let mut build = project("builder"); + build = build + .file("Cargo.toml", r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [features] + foo = [] + + [[bin]] + name = "foo" + "#) + .file("src/foo.rs", format!(r#" + use std::os; + use std::io::fs::PathExtensions; + fn main() {{ + let _ncpus = os::getenv("NUM_JOBS").unwrap(); + let _feat = os::getenv("CARGO_FEATURE_FOO").unwrap(); + let debug = os::getenv("DEBUG").unwrap(); + assert_eq!(debug.as_slice(), "true"); + + let opt = os::getenv("OPT_LEVEL").unwrap(); + assert_eq!(opt.as_slice(), "0"); + + let opt = os::getenv("PROFILE").unwrap(); + assert_eq!(opt.as_slice(), "compile"); + + let out = os::getenv("OUT_DIR").unwrap(); + assert!(out.as_slice().starts_with(r"{0}")); + assert!(Path::new(out).is_dir()); + + let out = os::getenv("DEP_BAR_BAR_OUT_DIR").unwrap(); + assert!(out.as_slice().starts_with(r"{0}")); + assert!(Path::new(out).is_dir()); + + let out = os::getenv("CARGO_MANIFEST_DIR").unwrap(); + let p1 = Path::new(out); + let p2 = os::make_absolute(&Path::new(file!()).dir_path().dir_path()); + assert!(p1 == p2, "{{}} != {{}}", p1.display(), p2.display()); + }} + "#, + p.root().join("target").join("native").display())); + assert_that(build.cargo_process("build").arg("--features").arg("foo"), + execs().with_status(0)); + + + p = p + .file("Cargo.toml", format!(r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + build = '{}' + + [features] + foo = [] + + [[bin]] + name = "foo" + + [dependencies.bar-bar] + path = '{}' + "#, build.bin("foo").display(), bar.root().display())) + .file("src/foo.rs", r#" + fn main() {} + "#); + assert_that(p.cargo_process("build").arg("--features").arg("foo"), + execs().with_status(0)); +}) + +test!(old_custom_build_in_dependency { + let mut p = project("foo"); + let mut build = project("builder"); + build = build + .file("Cargo.toml", r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [[bin]] + name = "foo" + "#) + .file("src/foo.rs", format!(r#" + use std::os; + fn main() {{ + assert!(os::getenv("OUT_DIR").unwrap().as_slice() + .starts_with(r"{}")); + }} + "#, + p.root().join("target/native/bar-").display())); + assert_that(build.cargo_process("build"), execs().with_status(0)); + + + p = p + .file("Cargo.toml", r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [[bin]] + name = "foo" + [dependencies.bar] + path = "bar" + "#) + .file("src/foo.rs", r#" + extern crate bar; + fn main() { bar::bar() } + "#) + .file("bar/Cargo.toml", format!(r#" + [project] + + name = "bar" + version = "0.5.0" + authors = ["wycats@example.com"] + build = '{}' + "#, build.bin("foo").display())) + .file("bar/src/lib.rs", r#" + pub fn bar() {} + "#); + assert_that(p.cargo_process("build"), + execs().with_status(0)); +}) + +// tests that custom build in dep can be built twice in a row - issue 227 +test!(old_custom_build_in_dependency_twice { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [[bin]] + name = "foo" + [dependencies.bar] + path = "./bar" + "#) + .file("src/foo.rs", r#" + extern crate bar; + fn main() { bar::bar() } + "#) + .file("bar/Cargo.toml", format!(r#" + [project] + + name = "bar" + version = "0.0.1" + authors = ["wycats@example.com"] + build = '{}' + "#, "echo test")) + .file("bar/src/lib.rs", r#" + pub fn bar() {} + "#); + assert_that(p.cargo_process("build"), + execs().with_status(0)); + assert_that(p.process(cargo_dir().join("cargo")).arg("build"), + execs().with_status(0)); +}) diff --git a/tests/tests.rs b/tests/tests.rs index 6807fae6d..49ed62565 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -29,6 +29,7 @@ mod test_cargo; mod test_cargo_bench; mod test_cargo_clean; mod test_cargo_compile; +mod test_cargo_compile_old_custom_build; mod test_cargo_compile_git_deps; mod test_cargo_compile_path_deps; mod test_cargo_test; -- 2.30.2